﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LiveSequence.Suite.Properties;


namespace LiveSequence.Suite.Controllers
{
  public class SearchingTreeViewController
  {
    private ToolStripItem[] _aToolStripItems;
    private ToolStripComboBox _toolStripComboBox;
    private ToolStripButton _toolStripButton;
    private TreeView _treeView;


    public event EventHandler SearchText;

    public SearchingTreeViewController(TreeView treeView, ToolStrip toolStrip)
    {
      _toolStripButton = new ToolStripButton();
      _toolStripButton.Image = Resources.SearchNext.ToBitmap();
      _toolStripComboBox = new ToolStripComboBox();
      _aToolStripItems = new ToolStripItem[] {_toolStripComboBox, _toolStripButton};

      _toolStripComboBox.KeyDown += new KeyEventHandler(_toolStripComboBox_KeyDown);
      _toolStripButton.Click += new EventHandler(_toolStripButton_Click);

      _treeView = treeView;
      toolStrip.Items.AddRange(_aToolStripItems);
      
    }

    public ToolStripItem[] ToolStripItems
    {
      get { return _aToolStripItems; }
    }

    public string SearchedText
    {
      get { return _toolStripComboBox.Text; }
      set { _toolStripComboBox.Text = value; }
    }

    void _toolStripButton_Click(object sender, EventArgs e)
    {
      OnSearchText();
    }

    void _toolStripComboBox_KeyDown(object sender, KeyEventArgs e)
    {
      // OnSearchText();
    }

    void OnSearchText()
    {
      _toolStripComboBox.ComboBox.Items.Add(_toolStripComboBox.ComboBox.Text);

      if(SearchText!=null)
      {
        SearchText(_treeView, EventArgs.Empty);
      }
    }
  }
}
